package yz.zookeeper;

import org.apache.zookeeper.*;

import java.io.IOException;

public class zookeeperDemo2 {
    public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
        ZooKeeper zooKeeper = new ZooKeeper("master:2181,node1:2181,node2:2181", 15000, new Watcher() {
            //对于接口对象创建时，要实现抽象函数
            @Override
            public void process(WatchedEvent watchedEvent) {
                System.out.println("连接在变化");
            }
        });

        /**
         * public String create(String path, byte[] data, List<ACL> acl, CreateMode createMode)
         *
         * OPEN_ACL_UNSAFE  创建节点，并且赋予读和写的权限
         *
         * CREATOR_ALL_ACL 创建节点有写的权限
         *
         * READ_ACL_UNSAFE 表示有读的权限
         *
         * CreateMode createMode:
         *      PERSISTENT   持久化节点（普通节点）
         *      PERSISTENT_SEQUENTIAL 持久化序列化节点
         *      EPHEMERAL  临时节点
         *      EPHEMERAL_SEQUENTIAL 临时序列化节点
         *      CONTAINER
         *      PERSISTENT_WITH_TTL
         *      PERSISTENT_SEQUENTIAL_WITH_TTL
         *
         */
        zooKeeper.create("/api","apiData".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        //创建临时节点
        //zooKeeper.create("/api/eph","apiData".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);


        zooKeeper.close();
    }
}
